package main

import (
	"flag"
	"fmt"
	"ginDemo/aa"
	_ "ginDemo/aa"
	"ginDemo/apis"
	"ginDemo/common/middleware"
	"ginDemo/common/version"
	"time"

	"gitee.com/clearluo/gotools/util"
	"gitee.com/clearluo/gotools/zaplog"
	"github.com/gin-gonic/gin"
)

func main() {
	checkVersion := flag.Bool("v", false, "")
	flag.Parse()
	if *checkVersion {
		fmt.Println(version.PrintVersion())
		return
	}
	go util.MonitorStatus(time.Minute)
	if version.IsDevelopment() {
		gin.SetMode(gin.DebugMode)
	} else {
		gin.SetMode(gin.ReleaseMode)
		gin.DisableConsoleColor()
	}
	engine := gin.New()
	engine.Use(middleware.LoggerToFile())
	// Recovery 中间件会 recover 任何 panic。如果有 panic 的话，会写入 500。
	engine.Use(gin.Recovery())
	//engine.GET("/ping", func(c *gin.Context) {
	//	zaplog.Warn("/ping")
	//	c.JSONP(200, gin.H{
	//		"message": "pong",
	//	})
	//})
	//engine.POST("/pingPost", func(c *gin.Context) {
	//	req := ReqDataT{}
	//	c.BindJSON(&req)
	//	//time.Sleep(time.Second * 15)
	//	c.JSON(200, gin.H{
	//		"id": req.Id,
	//	})
	//})
	apis.Router(engine)
	addr := fmt.Sprintf(":%v", aa.GetOutHttpPort())
	if err := engine.Run(addr); err != nil {
		zaplog.Warn("err")
		panic(err)
	}
}

type ReqDataT struct {
	Id string `json:"id"`
}
